package org.example.Soution002;

import java.util.ArrayList;
import java.util.List;

public class SubSetsSolution {
    public static void main(String[] args) {
        SubSetsSolution solution = new SubSetsSolution();
        int[] nums={1};
        System.out.println(solution.subsets(nums));
    }

    List<List<Integer>> result = new ArrayList<>();
    public List<List<Integer>> subsets(int[] nums) {
        //无论如何先放入一个空集
        result.add(new ArrayList<>());
        for(int i=0; i<nums.length; i++) {
            List<Integer> list=new ArrayList<>();
            list.add(nums[i]);
            subsetsCore(nums,i,nums.length,list);
        }
        return result;
    }

    public void subsetsCore(int[] nums, int position, int length, List<Integer> pathList) {
        if(position==length-1){
            result.add(pathList);
            return;
        }
        //不加下一轮数字
        subsetsCore(nums,position+1,length,pathList);
        List<Integer> list=new ArrayList<>(pathList);
        list.add(nums[position+1]);
        subsetsCore(nums,position+1,length,list);
    }
}
